/* eslint-disable react/jsx-no-duplicate-props */
import React, {Component} from 'react'
import {Button, Form, Input, Radio, Select} from 'antd';
import {connect} from "react-redux";
import {removeEmptyField} from '../../../compoent/emptyFild';


const {Option} = Select;

class Add extends Component {
    state = {
        fileList: [],
        loading: false,
        picData: '',

    };

    onFinish = (values) => {
        const {type,current} = this.props
        if (type === '0') {
            if (values) {
                values.page = 1
                values.size = 10
                this.props.add(values).then(res => {
                    this.props.vcsList({page: 1, size: 10})
                })
            }
        }
        else if (type === '1') {
            //编辑接口
            if (values) {
                values.id = this.props.record.id
                this.props.upd(values).then(res => {
                    this.props.vcsList({page: this.props.current, size: 10})
                })
            }

        }
        this.props.handleCancel()

    };

    onFinishFailed = (errorInfo) => {

    };

    render() {
        const {record} = this.props
        return (
            <div>
                <Form
                    name="basic"
                    labelCol={{span: 6}}
                    wrapperCol={{span: 14}}
                    initialValues={{remember: true}}
                    onFinish={this.onFinish}
                    onFinishFailed={this.onFinishFailed}
                    autoComplete="off"
                    initialValues={{
                        systemType: record ? record.systemType : 1,
                        version: record ? record.version : '',
                        status: record ? record.status : 1,
                        ifForceUpgrade: record ? record.ifForceUpgrade : 1,
                        downloadUrl: record ? record.downloadUrl : '',
                        upgradeDesc: record ? record.upgradeDesc : ''
                    }}
                >
                    <Form.Item
                        label="客户端："
                        name="systemType"
                        rules={[{required: true, message: '请选中客户端!'}]}
                    >
                        <Radio.Group options={[{label: 'android', value: 1}, {label: 'ios', value: 2}]}/>
                    </Form.Item>
                    <Form.Item
                        label="下载地址："
                        name="downloadUrl"
                        rules={[{required: true, message: '请输入下载地址!'}]}
                    >
                        <Input/>
                    </Form.Item><

                    Form.Item
                        label="版本号："
                        name="version"
                        rules={[{required: true, message: '请输版本号!'}]}
                    >
                        <Input/>
                    </Form.Item>

                    <Form.Item
                        label="强制更新："
                        name="ifForceUpgrade"
                        rules={[{required: true, message: '请选择是否强制更新!'}]}
                    >
                        <Radio.Group options={[{label: '是', value: 1}, {label: '否', value: 2}]}/>
                    </Form.Item>

                    <Form.Item
                        label="版本状态："
                        name="status"
                        rules={[{required: true, message: '请选择版本状态!'}]}
                    >
                        <Radio.Group options={[{label: '有效', value: 1}, {label: '无效', value: 0}]}/>
                    </Form.Item>

                    <Form.Item
                        label="更新描述"
                        name="upgradeDesc"
                         rules={[{ required: true, message: '请输入更新描述!' }]}
                    >
                        <Input.TextArea/>
                    </Form.Item>

                    <Form.Item wrapperCol={{offset: 8, span: 16}}>
                        <Button type="primary" htmlType="submit">
                            确认
                        </Button>
                        <Button type="primary" htmlType="reset" style={{marginLeft: 30}}>
                            重置
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        )
    }
}

const mapState = state => ({
    ...state.vcs

});

const mapDispatch = dispatch => ({
    ...dispatch.vcs
})

export default connect(mapState, mapDispatch)(Add);